﻿using HardcoreGame.Common.CustomSets;
using HardcoreGame.Content.Items.Ammo.SlingBullets;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;

namespace HardcoreGame.Content.Items.Weapons.Ranged.Slingshot
{
    public class LunarSlingshoot : ModItem
    {
        public override void SetStaticDefaults()
        {
            CustomItemSets.Slingshoot[Type] = true;
        }
        public override void SetDefaults()
        {
            Item.DefaultToRangedWeapon(1, ModContent.ItemType<StoneSlingBullet>(), 10, 6.5f, true);
            Item.damage = 120;
            Item.width = Item.height = 26;
            Item.useStyle = ItemUseStyleID.Shoot;
            Item.knockBack = 3.5f;
            Item.value = 40500;
            Item.rare = ItemRarityID.Red;
            Item item = Item;
            SoundStyle item2 = SoundID.Item5;
            item.UseSound = new SoundStyle?(item2.WithPitchOffset(0.2f));
        }
        public override void ModifyShootStats(Player player, ref Vector2 position, ref Vector2 velocity, ref int type, ref int damage, ref float knockback)
        {
            int fragmentCount = Main.rand.Next(2, 4); 
            for (int i = 0; i < fragmentCount; i++)
            {
                Vector2 fragmentVelocity = velocity.RotatedByRandom(MathHelper.ToRadians(30)) * 0.7f; 
                Projectile.NewProjectile(
                    player.GetSource_FromThis(),
                    position,
                    fragmentVelocity,
                    ModContent.ProjectileType<Projectiles.Ammo.LuminiteFragment>(), 
                    (int)(damage * 0.4f), 
                    knockback * 0.5f,
                    player.whoAmI
                );
            }
        }
        public override Vector2? HoldoutOffset()
        {
            return new Vector2?(new Vector2(-2f, -2f));
        }
        public override void AddRecipes()
        {
            Recipe modRecipe = Recipe.Create(Type, 1);
            modRecipe.AddIngredient(ItemID.LunarBar, 10);
            modRecipe.AddTile(TileID.LunarCraftingStation);
            modRecipe.Register();
        }
    }
}
